package com.dhj.jvmstudy.chapter05;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试 MinorGC、MajorGC、FullGC
 *
 * -Xms9m -Xmx9m -XX:+PrintGCDetails
 */
public class GCTest {

    public static void main(String[] args) {
        int i = 0;
        try {
            List<String> list = new ArrayList<>();
            String str = "dhj";
            while (true) {
                list.add(str);
                str = str + "_" + str;
                i++;
            }

            // OutOfMemoryError 并非异常，所以要捕获Throwable 错误及异常的顶级类才行
        } catch (Throwable t) {
            t.printStackTrace();
            System.out.println("遍历次数：" + i);
        }
    }

}
